<template>
  <div class="paper-detail" v-loading="loading">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <div class="title-section">
          <el-button @click="goBack" :icon="ArrowLeft" circle />
          <div>
            <h1>{{ paper?.title || '试卷详情' }}</h1>
            <p>查看试卷详细信息和考试统计</p>
          </div>
        </div>
        <div class="header-actions">
          <el-button @click="previewPaper">
            <el-icon><View /></el-icon>
            预览试卷
          </el-button>
          <el-button type="primary" @click="editPaper">
            <el-icon><Edit /></el-icon>
            编辑试卷
          </el-button>
          <el-dropdown @command="handleCommand">
            <el-button type="success">
              <el-icon><Operation /></el-icon>
              操作<el-icon><ArrowDown /></el-icon>
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="copy">复制试卷</el-dropdown-item>
                <el-dropdown-item command="export">导出试卷</el-dropdown-item>
                <el-dropdown-item command="distribute">分发试卷</el-dropdown-item>
                <el-dropdown-item command="statistics" divided>统计分析</el-dropdown-item>
                <el-dropdown-item command="archive" v-if="paper?.status !== 'archived'">
                  归档试卷
                </el-dropdown-item>
                <el-dropdown-item command="restore" v-if="paper?.status === 'archived'">
                  恢复试卷
                </el-dropdown-item>
                <el-dropdown-item command="delete" divided>删除试卷</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>

    <div class="content-container">
      <el-row :gutter="24">
        <!-- 左侧主要内容 -->
        <el-col :span="16">
          <!-- 基本信息 -->
          <el-card class="info-card">
            <template #header>
              <div class="card-header">
                <span>基本信息</span>
                <div class="status-tags">
                  <el-tag :type="getTypeColor(paper?.paper_type)">
                    {{ getTypeLabel(paper?.paper_type) }}
                  </el-tag>
                  <el-tag :type="getStatusColor(paper?.status)">
                    {{ getStatusLabel(paper?.status) }}
                  </el-tag>
                </div>
              </div>
            </template>

            <el-descriptions :column="2" border>
              <el-descriptions-item label="试卷标题">
                {{ paper?.title }}
              </el-descriptions-item>
              <el-descriptions-item label="试卷类型">
                <el-tag :type="getTypeColor(paper?.paper_type)">
                  {{ getTypeLabel(paper?.paper_type) }}
                </el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="总分">
                {{ paper?.total_score }} 分
              </el-descriptions-item>
              <el-descriptions-item label="考试时长">
                {{ paper?.duration }} 分钟
              </el-descriptions-item>
              <el-descriptions-item label="题目总数">
                {{ paper?.total_questions }} 题
              </el-descriptions-item>
              <el-descriptions-item label="及格分数">
                {{ paper?.passing_score }} 分
              </el-descriptions-item>
              <el-descriptions-item label="创建人">
                {{ paper?.creator_name }}
              </el-descriptions-item>
              <el-descriptions-item label="来源模板">
                <el-link
                  v-if="paper?.template_name"
                  type="info"
                  @click="viewTemplate(paper.template_id)"
                >
                  {{ paper.template_name }}
                </el-link>
                <span v-else class="text-placeholder">无模板</span>
              </el-descriptions-item>
              <el-descriptions-item label="创建时间" :span="2">
                {{ formatDate(paper?.created_at) }}
              </el-descriptions-item>
              <el-descriptions-item label="更新时间" :span="2">
                {{ formatDate(paper?.updated_at) }}
              </el-descriptions-item>
            </el-descriptions>

            <div class="paper-description" v-if="paper?.description">
              <h4>试卷描述</h4>
              <p>{{ paper.description }}</p>
            </div>
          </el-card>

          <!-- 试卷结构 -->
          <el-card class="structure-card">
            <template #header>
              <div class="card-header">
                <span>试卷结构</span>
                <span class="section-count">共 {{ paper?.sections?.length || 0 }} 个部分</span>
              </div>
            </template>

            <div class="sections-container">
              <div
                v-for="(section, index) in paper?.sections || []"
                :key="section.id"
                class="section-item"
              >
                <div class="section-header">
                  <div class="section-info">
                    <span class="section-number">{{ index + 1 }}</span>
                    <h3>{{ section.title }}</h3>
                    <el-tag size="small">{{ section.question_type }}</el-tag>
                  </div>
                  <div class="section-stats">
                    <span>{{ section.question_count }} 题</span>
                    <span>{{ section.total_score }} 分</span>
                  </div>
                </div>

                <div class="section-content">
                  <el-row :gutter="20">
                    <el-col :span="8">
                      <div class="stat-item">
                        <span class="label">每题分值：</span>
                        <span class="value">{{ section.score_per_question }} 分</span>
                      </div>
                    </el-col>
                    <el-col :span="8">
                      <div class="stat-item">
                        <span class="label">题目数量：</span>
                        <span class="value">{{ section.question_count }} 题</span>
                      </div>
                    </el-col>
                    <el-col :span="8">
                      <div class="stat-item">
                        <span class="label">总分值：</span>
                        <span class="value">{{ section.total_score }} 分</span>
                      </div>
                    </el-col>
                  </el-row>

                  <div class="difficulty-distribution" v-if="section.difficulty_distribution">
                    <h4>难度分布</h4>
                    <div class="difficulty-chart">
                      <div
                        v-for="(count, difficulty) in section.difficulty_distribution"
                        :key="difficulty"
                        class="difficulty-item"
                      >
                        <span class="difficulty-label">{{ getDifficultyLabel(difficulty) }}</span>
                        <div class="difficulty-bar">
                          <div
                            class="difficulty-fill"
                            :class="difficulty"
                            :style="{ width: getDifficultyPercent(section, difficulty) }"
                          ></div>
                        </div>
                        <span class="difficulty-count">{{ count }} 题</span>
                      </div>
                    </div>
                  </div>
                </div>

                <div class="section-actions">
                  <el-button size="small" @click="viewSectionQuestions(section)">
                    查看题目
                  </el-button>
                  <el-button size="small" @click="analyzeSection(section)">
                    题目分析
                  </el-button>
                </div>
              </div>
            </div>
          </el-card>

          <!-- 配置信息 -->
          <el-card class="config-card">
            <template #header>
              <span>配置信息</span>
            </template>

            <el-row :gutter="20">
              <el-col :span="12">
                <div class="config-item">
                  <h4>考试设置</h4>
                  <el-descriptions :column="1" size="small">
                    <el-descriptions-item label="随机题目顺序">
                      {{ paper?.config?.random_order ? '是' : '否' }}
                    </el-descriptions-item>
                    <el-descriptions-item label="随机选项顺序">
                      {{ paper?.config?.random_options ? '是' : '否' }}
                    </el-descriptions-item>
                    <el-descriptions-item label="防作弊模式">
                      {{ paper?.config?.anti_cheating ? '开启' : '关闭' }}
                    </el-descriptions-item>
                  </el-descriptions>
                </div>
              </el-col>
              <el-col :span="12">
                <div class="config-item">
                  <h4>显示设置</h4>
                  <el-descriptions :column="1" size="small">
                    <el-descriptions-item label="显示总分">
                      {{ paper?.config?.show_total_score ? '显示' : '隐藏' }}
                    </el-descriptions-item>
                    <el-descriptions-item label="显示计时">
                      {{ paper?.config?.show_timer ? '显示' : '隐藏' }}
                    </el-descriptions-item>
                    <el-descriptions-item label="显示答案">
                      {{ paper?.config?.show_answers ? '显示' : '隐藏' }}
                    </el-descriptions-item>
                  </el-descriptions>
                </div>
              </el-col>
            </el-row>
          </el-card>
        </el-col>

        <!-- 右侧统计信息 -->
        <el-col :span="8">
          <!-- 考试统计 -->
          <el-card class="stats-card">
            <template #header>
              <span>考试统计</span>
            </template>

            <div class="stats-grid">
              <div class="stat-box">
                <div class="stat-value">{{ paper?.exam_count || 0 }}</div>
                <div class="stat-label">考试次数</div>
              </div>
              <div class="stat-box">
                <div class="stat-value">{{ paper?.avg_score || 0 }}</div>
                <div class="stat-label">平均分</div>
              </div>
              <div class="stat-box">
                <div class="stat-value">{{ paper?.pass_rate || 0 }}%</div>
                <div class="stat-label">及格率</div>
              </div>
              <div class="stat-box">
                <div class="stat-value">{{ paper?.highest_score || 0 }}</div>
                <div class="stat-label">最高分</div>
              </div>
              <div class="stat-box">
                <div class="stat-value">{{ paper?.lowest_score || 0 }}</div>
                <div class="stat-label">最低分</div>
              </div>
              <div class="stat-box">
                <div class="stat-value">{{ getDifficultyLevel(paper) }}</div>
                <div class="stat-label">难度等级</div>
              </div>
            </div>

            <div class="score-distribution" v-if="paper?.score_distribution">
              <h4>分数分布</h4>
              <div class="score-chart">
                <div
                  v-for="(count, range) in paper.score_distribution"
                  :key="range"
                  class="score-range"
                >
                  <span class="range-label">{{ range }}</span>
                  <div class="score-bar">
                    <div
                      class="score-fill"
                      :style="{ width: getScoreRangePercent(range) }"
                    ></div>
                  </div>
                  <span class="score-count">{{ count }} 人</span>
                </div>
              </div>
            </div>
          </el-card>

          <!-- 难度分析 -->
          <el-card class="difficulty-card">
            <template #header>
              <span>难度分析</span>
            </template>

            <div class="difficulty-analysis">
              <div class="overall-difficulty">
                <div class="difficulty-label">整体难度</div>
                <div class="difficulty-level">
                  <el-rate
                    :model-value="getDifficultyLevel(paper)"
                    disabled
                    show-score
                    text-color="#ff9900"
                  />
                </div>
              </div>

              <div class="difficulty-stats">
                <h4>题目难度分布</h4>
                <div class="difficulty-chart">
                  <div
                    v-for="(count, difficulty) in paper?.difficulty_stats || {}"
                    :key="difficulty"
                    class="difficulty-stat"
                  >
                    <div class="stat-label">{{ getDifficultyLabel(difficulty) }}</div>
                    <div class="stat-bar">
                      <div
                        class="stat-fill"
                        :class="difficulty"
                        :style="{ width: getOverallDifficultyPercent(difficulty) }"
                      ></div>
                    </div>
                    <div class="stat-count">{{ count }} 题</div>
                  </div>
                </div>
              </div>
            </div>
          </el-card>

          <!-- 考试记录 -->
          <el-card class="records-card">
            <template #header>
              <div class="card-header">
                <span>最近考试</span>
                <el-button size="small" text @click="viewAllExams">
                  查看全部
                </el-button>
              </div>
            </template>

            <div class="exam-list">
              <div
                v-for="exam in recentExams"
                :key="exam.id"
                class="exam-item"
                @click="viewExam(exam)"
              >
                <div class="exam-info">
                  <div class="exam-title">{{ exam.exam_name }}</div>
                  <div class="exam-meta">
                    <span class="exam-score">{{ exam.score }}分</span>
                    <span class="exam-status" :class="getExamStatusClass(exam.status)">
                      {{ getExamStatusLabel(exam.status) }}
                    </span>
                  </div>
                  <div class="exam-time">{{ formatDate(exam.start_time) }}</div>
                </div>
                <el-icon class="exam-arrow"><ArrowRight /></el-icon>
              </div>
            </div>

            <div v-if="recentExams.length === 0" class="empty-exams">
              <el-empty description="暂无考试记录" :image-size="80" />
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 分发试卷对话框 -->
    <DistributePaperDialog
      v-model="showDistributeDialog"
      :paper="paper"
      @success="handleDistributeSuccess"
    />
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  ArrowLeft, Edit, View, Operation, ArrowDown, ArrowRight
} from '@element-plus/icons-vue'
import { examPaperApi } from '@/api/examPaper'
import DistributePaperDialog from './components/DistributePaperDialog.vue'
import { format } from 'date-fns'

const router = useRouter()
const route = useRoute()

// 响应式数据
const paper = ref(null)
const loading = ref(false)
const showDistributeDialog = ref(false)
const recentExams = ref([])

// 方法
const loadPaper = async () => {
  try {
    loading.value = true
    const paperId = route.params.id
    const response = await examPaperApi.getPaper(paperId)
    paper.value = response.data

    // 加载考试记录
    await loadExamRecords()
  } catch (error) {
    console.error('Failed to load paper:', error)
    ElMessage.error('加载试卷详情失败')
    router.push('/exam-paper/papers')
  } finally {
    loading.value = false
  }
}

const loadExamRecords = async () => {
  try {
    const response = await examPaperApi.getPaperExams(route.params.id, {
      page_size: 5,
      ordering: '-start_time'
    })
    recentExams.value = response.data.results || []
  } catch (error) {
    console.error('Failed to load exam records:', error)
  }
}

const goBack = () => {
  router.push('/exam-paper/papers')
}

const previewPaper = () => {
  router.push(`/exam-paper/papers/${route.params.id}/preview`)
}

const editPaper = () => {
  router.push(`/exam-paper/papers/${route.params.id}/edit`)
}

const viewTemplate = (templateId: string) => {
  router.push(`/exam-paper/templates/${templateId}`)
}

const viewSectionQuestions = (section: any) => {
  router.push(`/exam-paper/papers/${route.params.id}/sections/${section.id}/questions`)
}

const analyzeSection = (section: any) => {
  router.push(`/exam-paper/papers/${route.params.id}/sections/${section.id}/analysis`)
}

const handleCommand = async (command: string) => {
  switch (command) {
    case 'copy':
      await copyPaper()
      break
    case 'export':
      await exportPaper()
      break
    case 'distribute':
      distributePaper()
      break
    case 'statistics':
      viewStatistics()
      break
    case 'archive':
      await archivePaper()
      break
    case 'restore':
      await restorePaper()
      break
    case 'delete':
      await deletePaper()
      break
  }
}

const copyPaper = async () => {
  try {
    const response = await examPaperApi.copyPaper(route.params.id)
    ElMessage.success('试卷复制成功')
    router.push(`/exam-paper/papers/${response.data.id}`)
  } catch (error) {
    console.error('Failed to copy paper:', error)
    ElMessage.error('试卷复制失败')
  }
}

const exportPaper = async () => {
  try {
    const response = await examPaperApi.exportPaper(route.params.id)
    const blob = new Blob([response.data])
    const url = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = url
    link.download = `${paper.value.title}.json`
    link.click()
    window.URL.revokeObjectURL(url)
    ElMessage.success('试卷导出成功')
  } catch (error) {
    console.error('Failed to export paper:', error)
    ElMessage.error('试卷导出失败')
  }
}

const distributePaper = () => {
  showDistributeDialog.value = true
}

const viewStatistics = () => {
  router.push(`/exam-paper/papers/${route.params.id}/statistics`)
}

const archivePaper = async () => {
  try {
    await examPaperApi.updatePaper(route.params.id, { status: 'archived' })
    ElMessage.success('试卷归档成功')
    loadPaper()
  } catch (error) {
    console.error('Failed to archive paper:', error)
    ElMessage.error('试卷归档失败')
  }
}

const restorePaper = async () => {
  try {
    await examPaperApi.updatePaper(route.params.id, { status: 'published' })
    ElMessage.success('试卷恢复成功')
    loadPaper()
  } catch (error) {
    console.error('Failed to restore paper:', error)
    ElMessage.error('试卷恢复失败')
  }
}

const deletePaper = async () => {
  try {
    await ElMessageBox.confirm(
      `确定要删除试卷"${paper.value.title}"吗？此操作不可恢复。`,
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )

    await examPaperApi.deletePaper(route.params.id)
    ElMessage.success('试卷删除成功')
    router.push('/exam-paper/papers')
  } catch (error) {
    if (error !== 'cancel') {
      console.error('Failed to delete paper:', error)
      ElMessage.error('试卷删除失败')
    }
  }
}

const viewExam = (exam: any) => {
  router.push(`/examinations/${exam.id}`)
}

const viewAllExams = () => {
  router.push(`/examinations?paper=${route.params.id}`)
}

const handleDistributeSuccess = () => {
  showDistributeDialog.value = false
  ElMessage.success('试卷分发成功')
}

// 辅助方法
const getTypeColor = (type: string) => {
  const colors = {
    formal: 'primary',
    mock: 'success',
    practice: 'warning',
    competition: 'danger'
  }
  return colors[type] || 'info'
}

const getTypeLabel = (type: string) => {
  const labels = {
    formal: '正式考试',
    mock: '模拟考试',
    practice: '练习试卷',
    competition: '竞赛试卷'
  }
  return labels[type] || type
}

const getStatusColor = (status: string) => {
  const colors = {
    draft: 'info',
    pending: 'warning',
    published: 'success',
    archived: 'info'
  }
  return colors[status] || 'info'
}

const getStatusLabel = (status: string) => {
  const labels = {
    draft: '草稿',
    pending: '待审核',
    published: '已发布',
    archived: '已归档'
  }
  return labels[status] || status
}

const getDifficultyLabel = (difficulty: string) => {
  const labels = {
    easy: '简单',
    medium: '中等',
    hard: '困难'
  }
  return labels[difficulty] || difficulty
}

const getDifficultyPercent = (section: any, difficulty: string) => {
  const distribution = section.difficulty_distribution || {}
  const total = Object.values(distribution).reduce((sum: number, count: number) => sum + count, 0)
  if (total === 0) return '0%'
  const percent = ((distribution[difficulty] || 0) / total * 100).toFixed(1)
  return `${percent}%`
}

const getOverallDifficultyPercent = (difficulty: string) => {
  const stats = paper.value?.difficulty_stats || {}
  const total = Object.values(stats).reduce((sum: number, count: number) => sum + count, 0)
  if (total === 0) return '0%'
  const percent = ((stats[difficulty] || 0) / total * 100).toFixed(1)
  return `${percent}%`
}

const getDifficultyLevel = (paperData: any) => {
  const stats = paperData?.difficulty_stats || {}
  const total = Object.values(stats).reduce((sum: number, count: number) => sum + count, 0)
  if (total === 0) return 1

  const weightedSum = (stats.easy || 0) * 1 + (stats.medium || 0) * 2 + (stats.hard || 0) * 3
  return Math.round(weightedSum / total)
}

const getScoreRangePercent = (range: string) => {
  const distribution = paper.value?.score_distribution || {}
  const maxCount = Math.max(...Object.values(distribution))
  const count = distribution[range] || 0
  if (maxCount === 0) return '0%'
  return `${(count / maxCount * 100).toFixed(1)}%`
}

const getExamStatusLabel = (status: string) => {
  const labels = {
    pending: '待开始',
    in_progress: '进行中',
    completed: '已完成',
    submitted: '已提交',
    graded: '已评分'
  }
  return labels[status] || status
}

const getExamStatusClass = (status: string) => {
  const classes = {
    pending: 'status-pending',
    in_progress: 'status-progress',
    completed: 'status-completed',
    submitted: 'status-submitted',
    graded: 'status-graded'
  }
  return classes[status] || ''
}

const formatDate = (dateString: string) => {
  return format(new Date(dateString), 'yyyy-MM-dd HH:mm')
}

// 生命周期
onMounted(() => {
  loadPaper()
})
</script>

<style scoped>
.paper-detail {
  padding: 24px;
  background-color: var(--el-bg-color-page);
  min-height: calc(100vh - 64px);
}

.page-header {
  margin-bottom: 24px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-section h1 {
  margin: 0 0 8px 0;
  font-size: 28px;
  color: var(--el-text-color-primary);
}

.title-section p {
  margin: 0;
  color: var(--el-text-color-regular);
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.content-container {
  margin-bottom: 24px;
}

.info-card {
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-tags {
  display: flex;
  gap: 8px;
}

.paper-description {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--el-border-color-lighter);
}

.paper-description h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--el-text-color-primary);
}

.paper-description p {
  margin: 0;
  color: var(--el-text-color-regular);
  line-height: 1.6;
}

.structure-card {
  margin-bottom: 24px;
}

.section-count {
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.sections-container {
  space-y: 16px;
}

.section-item {
  border: 1px solid var(--el-border-color-lighter);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background-color: var(--el-bg-color);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-number {
  width: 24px;
  height: 24px;
  background-color: var(--el-color-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.section-info h3 {
  margin: 0;
  font-size: 16px;
  color: var(--el-text-color-primary);
}

.section-stats {
  display: flex;
  gap: 16px;
  font-size: 14px;
  color: var(--el-text-color-regular);
}

.section-content {
  margin-bottom: 16px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}

.stat-item .label {
  color: var(--el-text-color-regular);
}

.stat-item .value {
  color: var(--el-text-color-primary);
  font-weight: 500;
}

.difficulty-distribution {
  margin-top: 16px;
}

.difficulty-distribution h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--el-text-color-primary);
}

.difficulty-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.difficulty-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.difficulty-label {
  width: 40px;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.difficulty-bar {
  flex: 1;
  height: 6px;
  background-color: var(--el-fill-color-lighter);
  border-radius: 3px;
  overflow: hidden;
}

.difficulty-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.difficulty-fill.easy {
  background-color: #67C23A;
}

.difficulty-fill.medium {
  background-color: #E6A23C;
}

.difficulty-fill.hard {
  background-color: #F56C6C;
}

.difficulty-count {
  width: 40px;
  text-align: right;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.section-actions {
  display: flex;
  gap: 8px;
}

.config-card {
  margin-bottom: 24px;
}

.config-item {
  padding: 16px;
  border: 1px solid var(--el-border-color-lighter);
  border-radius: 8px;
}

.config-item h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--el-text-color-primary);
}

.stats-card {
  margin-bottom: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  text-align: center;
  padding: 16px 8px;
  border: 1px solid var(--el-border-color-lighter);
  border-radius: 8px;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--el-text-color-primary);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.score-distribution h4 {
  margin: 0 0 16px 0;
  font-size: 14px;
  color: var(--el-text-color-primary);
}

.score-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-range {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-label {
  width: 60px;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.score-bar {
  flex: 1;
  height: 6px;
  background-color: var(--el-fill-color-lighter);
  border-radius: 3px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  background-color: var(--el-color-primary);
  transition: width 0.3s ease;
}

.score-count {
  width: 50px;
  text-align: right;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.difficulty-card {
  margin-bottom: 24px;
}

.difficulty-analysis {
  space-y: 20px;
}

.overall-difficulty {
  margin-bottom: 20px;
}

.difficulty-label {
  font-size: 14px;
  color: var(--el-text-color-primary);
  margin-bottom: 8px;
}

.difficulty-stats h4 {
  margin: 16px 0 12px 0;
  font-size: 14px;
  color: var(--el-text-color-primary);
}

.difficulty-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.difficulty-stat {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-label {
  width: 40px;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.stat-bar {
  flex: 1;
  height: 8px;
  background-color: var(--el-fill-color-lighter);
  border-radius: 4px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.stat-fill.easy {
  background-color: #67C23A;
}

.stat-fill.medium {
  background-color: #E6A23C;
}

.stat-fill.hard {
  background-color: #F56C6C;
}

.stat-count {
  width: 40px;
  text-align: right;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.records-card {
  margin-bottom: 24px;
}

.exam-list {
  max-height: 300px;
  overflow-y: auto;
}

.exam-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--el-border-color-lighter);
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.exam-item:hover {
  background-color: var(--el-fill-color-lighter);
  border-radius: 4px;
  padding-left: 8px;
  padding-right: 8px;
}

.exam-item:last-child {
  border-bottom: none;
}

.exam-title {
  font-size: 14px;
  color: var(--el-text-color-primary);
  margin-bottom: 4px;
}

.exam-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.exam-score {
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.exam-status {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.status-pending {
  background-color: #E6F7FF;
  color: #1890FF;
}

.status-progress {
  background-color: #FFF7E6;
  color: #FA8C16;
}

.status-completed {
  background-color: #F6FFED;
  color: #52C41A;
}

.status-submitted {
  background-color: #FFF0F6;
  color: #EB2F96;
}

.status-graded {
  background-color: #F9F0FF;
  color: #722ED1;
}

.exam-time {
  font-size: 12px;
  color: var(--el-text-color-secondary);
}

.exam-arrow {
  color: var(--el-text-color-placeholder);
}

.empty-exams {
  text-align: center;
  padding: 20px 0;
}

.text-placeholder {
  color: var(--el-text-color-placeholder);
  font-style: italic;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .content-container .el-col:first-child {
    span: 24;
  }

  .content-container .el-col:last-child {
    span: 24;
  }
}

@media (max-width: 768px) {
  .paper-detail {
    padding: 16px;
  }

  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
</style>